# -*- coding: utf-8 -*-
# @Time    : 2021/4/20 17:29
# @Author  : JoSuper
# @File    : config.py
# @Software: PyCharm
# @Date    : 2021/4/20
import requests


class Config:
    username = ""
    password = ""
    last_year_course_id = "631"

    session = None
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'
    }
    login_url = "https://sso.xnjd.cn/login?service=http%3A%2F%2Fstudy.xnjd.cn%2F"

    @classmethod
    def login(cls):
        data = {
            "username": cls.username,
            "password": cls.password,
            "execution": "e1s1",
            "_eventId": "submit",
            "geolocation": "",
            "submit": "登录"
        }
        cls.session = requests.Session()
        r = cls.session.get(cls.login_url)
        resp = cls.session.post(cls.login_url, data, allow_redirects=False)
        if resp is None or resp.status_code != 302:
            raise Exception("登陆失败")
